package com.zelma.house.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;


import com.zelma.house.entity.AreaEntity;
import com.zelma.house.entity.ResourceEntity;
import com.zelma.house.service.AreaService;
import com.zelma.house.service.ResourceService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zelma.house.entity.SaleEntity;
import com.zelma.house.service.SaleService;
import com.zelma.common.utils.PageUtils;
import com.zelma.common.utils.R;



/**
 * 
 *
 * @author zelma
 * @email 1239115389@qq.com
 * @date 2022-01-07 14:58:16
 */
@RestController
@RequestMapping("house/sale")
public class SaleController {
    @Autowired
    private SaleService saleService;


    /**
     * 列表查询楼盘信息
     */
    @GetMapping("/saleList")
    public R saleList(@RequestParam Map<String, Object> params){
        PageUtils page = saleService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 新增楼盘信息
     */
    @PostMapping("/saleSave")
    public R saleSave(@RequestBody SaleEntity sale){
        return saleService.saleSave(sale);
    }

    @Autowired
    private ResourceService resourceService;
//省市县的实体类找出拉来
    /**
     * 销售楼盘详情界面
     *
     */
    @GetMapping("/saleDetails/{saleId}")
    public R saleDetails(@PathVariable("saleId") Integer saleId){
//        进入房源页面查询本楼盘所销售的房源信息
        List<ResourceEntity> resourceEntities = resourceService.saleDetails(saleId);
        return R.ok().put("saleDetails",resourceEntities);
    }



    /**
     * 楼盘房屋租赁详情界面
     */
    @GetMapping("/saleRentDetails/{saleId}")
    public R saleRentDetails(@PathVariable("saleId") Integer saleId){
//        进入房源页面查询本楼盘所销售的房源信息
        List<ResourceEntity> resourceEntities = resourceService.saleRentDetails(saleId);
        return R.ok().put("saleRentDetails",resourceEntities);
    }

    /**
     * 编辑信息(回显)
     */
    @GetMapping("/info/{saleId}")
    public R info(@PathVariable("saleId") Integer saleId){
		SaleEntity sale = saleService.getById(saleId);

        return R.ok().put("sale", sale);
    }


    /**
     * 编辑信息(修改)
     */
    @PostMapping("/saleUpdate")
    public R saleUpdate(@RequestBody SaleEntity sale){
		saleService.updateById(sale);
        return R.ok();
    }

    /**
     * 逻辑删除楼盘
     */
    @PostMapping("/delete/{saleId}")
    public R delete(@PathVariable("saleId") Integer saleId){
        SaleEntity byId = saleService.getById(saleId);

        return saleService.delete(byId);

    }

    /*
    * 查询经纪人列表在agent控制层已写好
    * 指定经纪人
    * */
    @PostMapping("/agentAppont/{saleId}/{agentId}")
    public R agentAppont(@PathVariable("saleId") Integer saleId,@PathVariable("agentId")Integer agentId){
//        获取楼盘信息
        SaleEntity byId = saleService.getById(saleId);

        return saleService.agentAppont(byId,agentId);

    }

    /**
     * 修改状态 是否正常开盘
     */
    @PostMapping("/updateStatus/{saleId}")
    public R updateStatus(@PathVariable("saleId") Integer saleId){
        SaleEntity byId = saleService.getById(saleId);

        return saleService.updateStatus(byId);

    }


}
